**** STATA/MP 18 ****


clear
set more off

use "3_clean_data_rl.dta"

factor trustparl_pre trustgov_pre trustpoli_pre trustparty_pre
alpha trustparl_pre trustgov_pre trustpoli_pre trustparty_pre
gen pol_trust_pre=(trustparl_pre+trustgov_pre+trustpoli_pre+trustparty_pre)
gen pol_trust_post=(trustparl_post+trustgov_post+trustpoli_post+trustparty_post)
lab  var pol_trust_pre pre_political_trust_index
lab  var pol_trust_post post_political_trust_index


sum pol_trust_pre
sum pol_trust_post


corr swd_post pol_trust_post
corr satisref swd_post
corr accept3 swd_post


********************Hypothesis I ***********************************************
ssc install cibar

* first-time winners vs. first-time losers
gen winners_losers=.
replace winners_losers=1 if group<5    //winners
replace winners_losers=2 if group>4		// losers 

** t-test of the difference
ttest accept1, by(winners_losers)	   
	   
************** Hypothesis II. FIGURE 3. Decision acceptance of a loss taking previous losses into account
// comparing decision acceptance among the groups who received as a third and 
// final outcome an unfavorable decision (LLL, WLL, LWL, WWL)

gen third_DA=.
recode third_DA(.=1) if group==2    //WWL   , NO LOSS
recode third_DA(.=2) if group==6 //LWL, ONE PREVIOUS LOSS
recode third_DA(.=2) if group==4  //WLL, ONE PREVIOUS LOSS
recode third_DA(.=3) if group==8    //LLL, TWO PREVIOUS LOSSES	
tab third_DA

catcibar accept3,over(third_DA) color(gs12 gs5 gs1) ylab(1(1)6,nogrid)

by third_DA, sort : summarize accept3	   

ttesti  254    3.929134    2.099053 256    3.210938    1.771904     
// no loss vs two losses 
ttesti  254  3.929134    2.099053 520 3.580769    1.932686
// no loss vs one previous loss 
ttesti   520    3.580769    1.932686  256    3.210938    1.771904
// one loss vs two losses 


*************** FIGURE 4 *************** 
gen amount=.
replace amount=1 if group==1  //WWW
replace amount=2 if group==5|group==3|group==2 //lost once, so LWW, WLW, WWL
replace amount=3 if group==7|group==6|group==4 //lost twice, LLW, LWL, WLL
replace amount=4 if group==8  // 3 times loser

catcibar satisref,over (amount) color(gs14 gs10 gs5 gs1) ylab(1(1)7,nogrid)

**** testing H3-H5 *******
* H3: Consecutive losers vs. discontinuous losers
gen LLL_LWL=. 
replace LLL_LWL=0 if group==8 // LLL
replace LLL_LWL=1 if group==6 // LWL

bysort LLL_LWL: sum pol_trust_pre 
bysort LLL_LWL: sum pol_trust_post 
bysort LLL_LWL: sum swd_pre 
bysort LLL_LWL: sum swd_post

ttest pol_trust_pre, by(LLL_LWL)
ttest pol_trust_post, by(LLL_LWL)

gen change_poltrust=(pol_trust_post-pol_trust_pre)
ttest change_poltrust, by(LLL_LWL)

ttest swd_pre, by(LLL_LWL)
ttest swd_post, by(LLL_LWL)
gen change_swd=(swd_post-swd_pre)
ttest change_swd, by(LLL_LWL)

ttest swd_pre== swd_post if group==8 // LLL
ttest swd_pre== swd_post if group==6 // LWL

ttest pol_trust_pre == pol_trust_post if group==8 // LLL
ttest pol_trust_pre == pol_trust_post if group==6 // LWL

* H4: Asymetic gap
gen LLL_WWW=.
replace LLL_WWW=0 if group==8 // LLL
replace LLL_WWW=1 if group==1 // WWW

ttest swd_pre, by(LLL_WWW)
ttest swd_post, by(LLL_WWW)
ttest change_swd, by(LLL_WWW)

ttest pol_trust_pre, by(LLL_WWW)
ttest pol_trust_post, by(LLL_WWW)
ttest change_poltrust, by(LLL_WWW)

ttest swd_pre== swd_post if group==8 // LLL
ttest swd_pre== swd_post if group==1 // WWW

ttest pol_trust_pre == pol_trust_post if group==8 // LLL
ttest pol_trust_pre == pol_trust_post if group==1 // WWW

* H5: News consumption

gen newsconsumption= tv+ newspaper+ radionews+ socialmedia+ internetnews
hist newsconsumption

reg accept3 i.amount##c.newsconsumption,ro  
estimates store a

reg satisref i.amount##c.newsconsumption,ro
estimates store b

reg change_swd i.amount##c.newsconsumption,ro
estimates store c

reg change_poltrust i.amount##c.newsconsumption,ro
estimates store d

coefplot (a, label (decision acceptance)) ///
         (b, label (process legitimacy)) ///
		 (c, label (change in swd)) ///
		 (d, label (chnage in poltrust)) ///
		 , ci(95) graphregion(color(white)) grid(none) xline(0, lcolor(gs10)) ciopts(recast(rcap)) drop(_cons)

************** FIGURE 5 ****************
reg change_swd ib(first).amount,ro //change in satisfaction with democracy
estimates store Model1

reg change_poltrust ib(first).amount,ro //change in political trust 
estimates store Model2

coefplot Model1 Model2, xline(0) drop(_cons)
 
***** TABLE 1 *****
// rescaling frustration to 0-1 scale
sum frustration, meanonly
// create the rescaled price
gen frust_rs = ( frustration - r(min) ) / ( r(max)-r(min) ) 

tab frustration
tab frust_rs

by amount, sort : summarize frust_rs

by amount, sort : summarize fair_process

 
*** table 3
reg fair_process frustration
estimates store m1

regress accept3 amount fair_process accept1 accept2
estimates store m2

regress satisref amount fair_process
estimates store m3

regress change_swd amount fair_process
estimates store m4

regress change_poltrust amount fair_process
estimates store m5

esttab m1 m2 m3 m4 m5 using "regressiontabel3.rtf", se r2 ar2 replace

****** appendices****
fre gender
fre age
fre edu
fre partisan

*


****** RESTRICTING THE ANALYSES TO THOSE WHO COMPLIED WITH THE treatment, I.E. MC1=1
reg accept3 i.amountoflosing2,ro
estimates store a


reg accept3 i.amountoflosing2 if MC1==1,ro
estimates store b

coefplot a b,drop(_cons) xline(0)

** satisref

reg satisref i.amount,ro
estimates store a


reg satisref i.amount if MC1==1,ro
estimates store b

coefplot a b,drop(_cons) xline(0)


** change in swd
reg satisref i.amountoflosing2,ro
estimates store a

reg change_swd i.amountoflosing2,ro
estimates store b

coefplot a b,drop(_cons) xline(0)

*

pwcorr accept1 accept3 satisref pol_trust_post swd_post, sig star(.05) obs

***
regress accept3 amount fair_process accept1 accept2 if decision2==0
estimates store m1

regress accept3 amount fair_process accept1 accept2 if decision2==0
estimates store m2

regress satisref amount fair_process if decision2==1
estimates store m3

regress satisref amount fair_process if decision2==1
estimates store m4

*
regress change_swd amount fair_process
estimates store m4

regress change_poltrust amount fair_process
estimates store m5

esttab m1 m2 m3 m4 m5 using "regressiontabel2.rtf", se r2 ar2 replace
*

** moderaing role of issue salience 

* saliency # H1

recode issuesal_divorce issuesal_baincome issuesal_womenrole issuesal_votingage issuesal_directelect (99=.)

/// the order of policy issues: womens role in the household, divorce and voting age 16 years. 

****** 
*
reg accept1 i.winners_losers issuesal_womenrole c.issuesal_womenrole#i.winners_losers,ro
estimates store a  // decision acceptance, winners_losers (1st time ones)
coefplot a, drop(_cons) xline(0)


reg accept1 i.winners_losers issuesal_womenrole c.issuesal_womenrole#i.winners_losers,ro
margins winners_losers,at(issuesal_womenrole=(1(1)5))
marginsplot,xdimensions(at(issuesal_womenrole))


reg accept3 i.third_DA issuesal_votingage c.issuesal_votingage#i.third_DA,ro
estimates store a  // third_DA - 1. wwl, 2. lwl 3. wll 4. lll
coefplot a, drop(_cons) xline(0)

***


reg satisref i.amount issuesal_divorce c.issuesal_divorce#i.amount,ro
estimates store a

reg satisref i.amount c.issuesal_womenrole c.issuesal_womenrole#i.amount,ro 
estimates store b

reg satisref i.amount c.issuesal_votingag c.issuesal_votingage#i.amount,ro 
estimates store c

coefplot a b c, drop(_cons) xline(0)

*

reg satisref i.amount c.issuesal_votingag c.issuesal_votingage#i.amount,ro 
margins amount,at(issuesal_votingag=(1(1)5))
marginsplot,xdimensions(at(issuesal_votingag))


reg change_swd i.amount issuesal_divorce c.issuesal_divorce#i.amount,ro
estimates store a

reg change_swd i.amount c.issuesal_womenrole c.issuesal_womenrole#i.amount,ro 
estimates store b

reg change_swd i.amount c.issuesal_votingag c.issuesal_votingage#i.amount,ro 
estimates store c

coefplot a b c, drop(_cons) xline(0)

* H4

gen www_lll=.
recode www_lll (.=1) if group==1
recode www_lll (.=2) if group==8

reg change_swd i.www_lll issuesal_divorce issuesal_womenrole issuesal_votingage c.issuesal_divorce#i.www_lll c.issuesal_womenrole#i.www_lll c.issuesal_votingage#i.www_lll
estimates store a

coefplot a, drop(_cons) xline(0)


****


** sub-group analysis among those who are willing to participate in referendums

// H1

reg accept1 winners_losers if willvoteref_pre>5,ro
reg accept3 third_DA if willvoteref_pre>5,ro

reg accept1 winners_losers if willvoteref_pre<5,ro

// results are robust

// H2

reg satisref amountoflosing2 if willvoteref_pre>5,ro
reg change_swd amountoflosing2 if willvoteref_pre>5,ro 


** presenting the main model together with other covariates
recode polintr (99=.)

reg accept3 i.amount gender age leftright polintr tv newspaper radionews socialmedia ib(3).partyid_party pol_trust_pre,ro  // I took the Fine Gael as a baseline category, the one in the government (minority gov). 
estimates store a

reg satisref i.amount gender age leftright polintr tv newspaper radionews socialmedia pol_trust_pre,ro
estimates store b

reg change_swd i.amount gender age leftright polintr tv newspaper radionews socialmedia pol_trust_pre,ro
estimates store c

reg change_poltrust i.amount gender age leftright polintr tv newspaper radionews socialmedia pol_trust_pre,ro
estimates store d

coefplot a b c d, ci(95) graphregion(color(white)) grid(none) xline(0, lcolor(gs10)) ciopts(recast(rcap)) keep (*.amount)

coefplot a,bylabel(Decision Acceptance)|| b, bylabel(Satisfaction w/ Referendums)||, 	graphregion(color(white)) grid(none) xline(0, lcolor(gs10)) ciopts(recast(rcap)) keep (*.amount) xline(0, lcolor(gs10))


coefplot c, bylabel(Satisfaction with Democracy)||d, bylabel(Political Trust)||, 	graphregion(color(white)) grid(none) xline(0, lcolor(gs10)) ciopts(recast(rcap)) keep (*.amount) xline(0, lcolor(gs10))



gen amount_winning=.
recode amount_winning (.=1) if group==8   //no winning
recode amount_winning (.=2) if group==7|group==6|group==5 // one winning
recode amount_winning (.=3) if group==4|group==3|group==2    //2 wins
recode amount_winning (.=4) if group==1 //3 winning


reg change_swd i.amount_winning,ro
estimates store a

reg satisref i.amount_winning,ro
estimates store b


coefplot a b,drop(_cons) xline(0)

*** among engaged

* 1-very interested, 2-quite interested, 3-hardly interested, 4-not at all interested. 
// reversing it so the greater numbers indicate greater interest
gen engaged=(5-polintr)

tab engaged

reg accept1 i.winners_losers if engaged>2,ro
estimates store a
reg accept3 i.third_DA if engaged>2,ro
estimates store b
reg satisref i.amount if engaged>2,ro
estimates store c
reg change_swd i.amount if engaged>2,ro
estimates store d

coefplot a b c d, xline(0) drop(_cons)

** change in SWD controlling for pre-SWD. app M. 

reg change_swd i.amount swd_pre,ro
estimates store d
coefplot d, xline(0)


*****

alpha angry outraged alarmed frustration

factor hopeful proud excited happy
alpha hopeful proud excited happy
gen positive=(hopeful+proud+excited+happy)
tab frustration
tab positive


cibar frust_rs,over(amount) ciopts(lcolor(black)) graphopts(ylab(0(0.10)0.7,nogrid) name(graph_1,replace))

sum pros, meanonly
gen pros_rs = ( pros - r(min) ) / ( r(max)-r(min) ) 

reg pros_rs c.frustration

// to do ttests with unbalanced samples....

// I create binary variables in order to do t-tests between numbers, etc. of losing
gen amount1=.
replace amount1=1 if amountoflosing==1	//no loss
replace amount1=2 if amountoflosing==2 //one loss

gen amount2=.
replace amount2=1 if amountoflosing==1 //no loss
replace amount2=2 if amountoflosing==3 //two losses

gen amount3=.
replace amount3=1 if amountoflosing==1 //no loss
replace amount3=2 if amountoflosing==4 //three losses

gen amount4=.
replace amount4=1 if amountoflosing==3 //no loss
replace amount4=2 if amountoflosing==4 //three losses

***


ttest frust_rs, by(amount1) unequal
ttest frust_rs, by(amount1)
ttest frust_rs, by(amount2)
ttest frust_rs, by(amount3)

ttest frust_rs, by(amount4)


*

reg positive i.amount,ro
estimates store a
reg frustration i.amount,ro
estimates store b
coefplot a b, xline(0) drop(_cons)

****

